<%-- 
    Document   : messages
    Created on : Mar 4, 2014, 10:36:09 PM
    Author     : Jordan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<c:set scope="request" var="title" value="Message"/>

<sql:setDataSource user="root" password="" driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost/bonix"/>

               <%
                Cookie cookie = null;
                Cookie[] cookies = null;
                // Get an array of Cookies associated with this domain
                cookies = request.getCookies();
                if( cookies != null ){
                   for (int i = 0; i < cookies.length; i++){
                        cookie = cookies[i];
                        if(cookie.getName().equals("username")){
                            %>
<sql:query var="getMessages">
    Select entry_id,sender,receiver,msg,sent_date,status from messages 
    where receiver = "<%out.print(""+cookie.getValue()+"");%>"
</sql:query>
                <%
                        }
                   }
                }
                %>
<!DOCTYPE html>
<html>
    <jsp:include page="head.jsp"/>

    <body>
        <jsp:include page="header.jsp"/>

        <div class="row">
            <div class="container">
                <div class="content row">

                    <div class="containerService">

                        <div class="panel-heading">
                            <ul class="navClient navClient-pills">
                                <li class="active"><a href='messages.jsp'> Message Inbox </a></li>
                                <li><a href='compose.jsp'> Compose Message </a></li>						
                                <li><a href='sendItems.jsp'> Sent Item </a></li>
                            </ul>
                        </div>

                        <div class="panel-body">
                            <br><hr>
                            <table class="table table-hover table-condensed">
                                <thead>  
                                    <tr>  
                                        <th></th>
                                        <th>STATUS </th>
                                        <th>MESSAGE FROM</th>  
                                        <th>DATE</th>  
                                        <th>MESSAGE</th>   
                                    </tr>  
                                </thead> 
                                <tbody>
                                    <c:forEach var="message" items="${getMessages.rows}">
                                        <c:if test="${message.status == 'unread'}"> 
                                            <tr class="warning"> 
                                                <td><span class="badge badge-info">NEW</span></td>
                                                <td class="text-left"><a href="checkMessage.jsp?entry_id=${message.entry_id}"/>${message.status}</td>
                                                <td class="text-left"><a href="checkMessage.jsp?entry_id=${message.entry_id}"/>${message.sender}</td>  
                                                <td class="text-left">${message.sent_date}</td>  
                                                <td class="text-left">${message.msg}</td>   
                                            </tr>  
                                        </c:if> 
                                        <c:if test="${message.status == 'read'}"> 
                                            <tr>      
                                                <td></td>
                                                <td class="text-left"><a href="checkMessage.jsp?entry_id=${message.entry_id}"/>${message.status}</td>
                                                <td class="text-left"><a href="checkMessage.jsp?entry_id=${message.entry_id}"/>${message.sender}</td>   
                                                <td class="text-left">${message.sent_date} </td>
                                                <td class="text-left">${message.msg} </td>                                                
                                            </tr>
                                        </c:if>
                                    </c:forEach>    
                                </tbody>
                            </table>
                        </div><!-- END panel-body -->

                        <!-- END panel-info -->
                    </div><!-- END containerService -->

                </div><!-- END CONTENT CONTENT ROW -->
            </div><!-- END CONTAINER -->
        </div><!-- END ROW -->

        <jsp:include page="footer.jsp"/>

    </body>
</html>
